package com.hzqy.web.ac.system;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hzqy.commons.utils.FileType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.alibaba.fastjson.JSON;
import com.hzqy.commons.utils.SystemConfigUtils;
import com.hzqy.service.system.SysUtilServiceBeen;

@Controller
@RequestMapping("/system/sys_util")
public class SysUtilAction {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	private static final String[] allowedFileType = new String[]{"png", "jpg", "gif", "zip", "jar", "tar", "docx", "doc", "xlsx", "xls", "flv", "mp4", "mp3", "mpg", "avi", "mov", "wmv"};

	@Resource
	private SysUtilServiceBeen sysUtilServiceBeen;

	
	@RequestMapping("/upload_excel")
	@ResponseBody 
	public Object uploadExcel(HttpServletRequest request ,MultipartHttpServletRequest multipart){
		String str = sysUtilServiceBeen.uploadExcelService(request,"组织对应的模板.xlsx",multipart);
		return str;
	}
	
	/**
	 * 读取生成excel，存到static文件下
	 * 
	 */
	@RequestMapping("/create_excel_for_model")
	@ResponseBody
	public Object createExcelForModel( HttpServletResponse response){
		
		String str =  sysUtilServiceBeen.createExcelForModelService();
		
		return str;
	}
	
	
	/**
	 * 获取修改时间
	 * 
	 */
	@RequestMapping("/md_time")
	@ResponseBody
	public String mdTime(){
			
		String filePath = SystemConfigUtils.getSysConfig("sysutil_downFile");
		String time = sysUtilServiceBeen.mdTimeService(filePath,"组织对应的模板数据.xlsx");
		return time;
	}
	
	
	/**
	 * 组织去重
	 * 
	 */
	/*@RequestMapping("/remove_duplicates_org")
	@ResponseBody
	public Object removeDuplicatesOrg(@RequestParam(value = "uploadify") MultipartFile file, 
			HttpServletResponse response, HttpSession session) throws Exception {
		if (FileType.checkFileType(file.getInputStream(), allowedFileType)) {
		response.setContentType("text/html;charset=UTF-8");
		String str = sysUtilServiceBeen.removeDuplicatesOrg(file);
		return str;
	}else {
			return "";
		}
	}*/
	
	/**
	 * 批量导入组织
	 * 
	 */
	/*@RequestMapping("/batch_insert_org")
	@ResponseBody
	public Object batchInsertOrg(@RequestParam(value = "uploadify") MultipartFile file,
			HttpServletResponse response) throws Exception {
		if (FileType.checkFileType(file.getInputStream(), allowedFileType)) {
		String str = sysUtilServiceBeen.batchInsertOrg(file);
		return str;
	}else {
			return "";
		}
	}*/
	
	/**
	 * 批量导入组织
	 * 
	 */
	/*@RequestMapping("/batch_insert_content")
	@ResponseBody
	public Object batchInsertContent(@RequestParam(value = "uploadify") MultipartFile file,
			int f_catalog_id,HttpSession session) throws Exception {
		if (FileType.checkFileType(file.getInputStream(), allowedFileType)) {
			String str = sysUtilServiceBeen.batchInsertContent(file, f_catalog_id, session);
			return str;
		} else {
			return "";
		}
	}*/
	
	
	
	/**   --------------  离线用户与订购清单导出工具  --------------   */
	
	/**
	 * 上传文件
	 * filePath: 文件存储完整路径 包括文件名
	 */
	/*@RequestMapping("/upload_file")
	@ResponseBody 
	public Object uploadFile(MultipartFile uploadify, String filePath) throws Exception {
		if (FileType.checkFileType(uploadify.getInputStream(), allowedFileType)) {
			return sysUtilServiceBeen.uploadFile(uploadify, filePath);
		} else {
			return null;
		}
	}*/
	
	/**
	 * 生成离线用户excel文件
	 */
	@RequestMapping("/generate_offline_user_excel")
	@ResponseBody 
	public Object generateOfflineUserExcel(){
		return sysUtilServiceBeen.generateOfflineUserExcel(SystemConfigUtils.getSysConfig("sysutil_downFile"));
	}
	
	/**
	 * 生成订购清单excel文件
	 */
	@RequestMapping("/generate_order_list_excel")
	@ResponseBody 
	public Object generateOrderListExcel(){
		return sysUtilServiceBeen.generateOrderListExcel(SystemConfigUtils.getSysConfig("sysutil_downFile"));
	}
	
	
	/**
	 * 匹配酒店清单用户模版
	 */
	@RequestMapping("/generate_user_list_model_excel")
	@ResponseBody 
	public Object generateUserListModelExcel(){
		return sysUtilServiceBeen.generateUserListModelExcel(SystemConfigUtils.getSysConfig("sysutil_downFile"));
	}
	/**   --------------  离线用户与订购清单导出工具  --------------   */
	
	
	/**
	 * 将活跃用户根据分组区分
	 */
	@RequestMapping("/generate_user_excel_by_group")
	@ResponseBody 
	public Object generateUserExcelByGroup(){
		return sysUtilServiceBeen.generateUserExcelByGroup(SystemConfigUtils.getSysConfig("sysutil_downFile"));
	}
	
	/**
	 * 删除文件
	 * filePath: 文件存储完整路径 包括文件名
	 */
	@RequestMapping("/delete_file")
	@ResponseBody 
	public Object deleteFile(String filePath){
		return sysUtilServiceBeen.deleteFile(filePath);
	}
	
	/**
	 * 批量导入订购清单
	 * 
	 */
	/*@RequestMapping("/batch_insert_order")
	@ResponseBody
	public Object batchInsertOrder(@RequestParam(value = "uploadify") MultipartFile file,
			HttpSession session) throws Exception{
		if (FileType.checkFileType(file.getInputStream(), allowedFileType)) {
		String str = sysUtilServiceBeen.batchInsertOrder(file,session);
		return str;
	}else {
			return "";
		}
	}*/
	
	/**
	 * 批量导入全平台用户清单
	 * 
	 */
	/*@RequestMapping("/batch_insert_allUser")
	@ResponseBody
	public Object batchInsertAllUser(@RequestParam(value = "uploadify") MultipartFile file,
			HttpSession session) throws Exception{
		if (FileType.checkFileType(file.getInputStream(), allowedFileType)) {
		String str = sysUtilServiceBeen.batchInsertAllUser(file,session);
		return str;
		}else {
			return "";
		}
	}*/
	
	/**
	 * 批量导入全平台BICP用户清单
	 * 
	 */
	/*@RequestMapping("/batch_insert_allBICPUser")
	@ResponseBody
	public Object batchInsertAllBICPUser(@RequestParam(value = "uploadify") MultipartFile file,
			HttpSession session) throws Exception{
		if (FileType.checkFileType(file.getInputStream(), allowedFileType)) {
		String str = sysUtilServiceBeen.batchInsertAllBICPUser(file,session);
		return str;
	}else {
			return "";
		}
	}*/
	
	/**
	 * 环球线下订购数据导入
	 * 
	 */
	/*@RequestMapping("/batch_insert_hq_order")
	@ResponseBody
	public Object batchInsertHQOrder(@RequestParam(value = "uploadify") MultipartFile file,
			HttpSession session) throws Exception{
		if (FileType.checkFileType(file.getInputStream(), allowedFileType)) {
		String str = sysUtilServiceBeen.batchInsertHQOrder(file,session);
		return str;
	}else {
			return "";
		}
	}*/
	
	/**
	 * 名师优课课程包导入
	 * 
	 */
	/*@RequestMapping("/batch_insert_MYSK_course")
	@ResponseBody
	public Object batchInsertMYSKCourse(@RequestParam(value = "uploadify") MultipartFile file,
			HttpSession session) throws Exception{
		if (FileType.checkFileType(file.getInputStream(), allowedFileType)) {
			String str = sysUtilServiceBeen.batchInsertMYSKCourse(file, session);
			return str;
		} else {
			return "";
		}
	}*/
	
	/**
	 * 名师优课视频包导入
	 * 
	 */
	/*@RequestMapping("/batch_insert_MYSK_lession")
	@ResponseBody
	public Object batchInsertMYSKLession(@RequestParam(value = "uploadify") MultipartFile file,
			HttpSession session){
		String str = sysUtilServiceBeen.batchInsertMYSKLession(file,session);
		return str;
	}*/
	
	/**
	 * 离网用户导入
	 * 
	 */
	/*@RequestMapping("/batch_insert_offitv_user")
	@ResponseBody
	public Object batchInsertOffITVUser(@RequestParam(value = "uploadify") MultipartFile file,
			HttpSession session) throws Exception {
		if (FileType.checkFileType(file.getInputStream(), allowedFileType)) {
			String str = sysUtilServiceBeen.batchInsertOffITVUser(file, session);
			return str;
		} else {
			return "";
		}
	}*/
	
	/**
	 * 月退订数据导入
	 * 
	 */
/*	@RequestMapping("/insertMonthUnsubscribeData")
	@ResponseBody
	public Object insertMonthUnsubscribeData(@RequestParam(value = "uploadify") MultipartFile file,
			HttpSession session)throws Exception {
		if (FileType.checkFileType(file.getInputStream(), allowedFileType)) {
		String str = sysUtilServiceBeen.insertMonthUnsubscribeData(file,session);
		return str;
	}else {
			return "";
		}
	}*/

	/**
	 * 生成月经分排名数据excel文件
	 */
	@RequestMapping("/generate_month_business_analysis_excel")
	@ResponseBody
	public Object generateMonthBusinessAnalysisExcel(){
		return sysUtilServiceBeen.generateMonthBusinessAnalysisExcel(SystemConfigUtils.getSysConfig("sysutil_downFile"));
	}
}
